using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Samples.SsbTransportChannel;
using SsbTransportTestSuite.Services;
using System.ServiceModel;

namespace SsbTransportTestSuite
{
    class TestTwoWayService : IOrderProcessing
    {
        #region IOrderProcessing Members

        public void BeginOrder(Order order)
        {

            Console.WriteLine("BeginOrder called");
             
        }

        public void AddOrderItem(OrderItem item)
        {

            Console.WriteLine("AddOrderItem called");
            if (item.Amount < 0)
            {
                SsbConversationGroupReceiver receiver = OperationContext.Current.Channel.GetProperty<SsbConversationGroupReceiver>();
                receiver.EndConversationWithError(300, "Order Amount cannot be less than 0");

            }
        }

        public void EndOrder()
        {
            Console.WriteLine("EndOrder called");
            SsbConversationGroupReceiver receiver = OperationContext.Current.Channel.GetProperty<SsbConversationGroupReceiver>();
            IOrderNotification response = receiver.GetCallback<IOrderNotification>();
            response.ConfirmOrder();
            response.UpdateOrderStatus(OrderStatus.Confirmed);

            response.UpdateOrderStatus(OrderStatus.Shipped);
            receiver.EndConversation();
        }

        #endregion
    }
}
